import { Controller, Get, Sse } from '@nestjs/common';
import { AppService } from './app.service';
import { Observable } from 'rxjs';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }

  @Sse('sse')
  sse() {
    return new Observable<any>((observer) => {
      setInterval(() => {
        observer.next({
          data: {
            message: 'Hello World' + Math.random(),
            time: new Date().toISOString(),
          },
        });
      }, 1000);
    });
  }
}
